const express = require('express')
const bodyParser = require('body-parser')
//错误返回模块
const returned = require('./error_returned/returned')
//用户信息路由
const userregister = require('./router/user')
const goods = require('./router/goods')
const cart = require('./router/cart')
const app = express()
app.listen(8848)

// 挂载中间件 获取opst请求  
app.use(bodyParser.urlencoded({extended:false}))

//挂载路由 用户属性
app.use('/user',userregister)

//商品详情
app.use('/goods/api',goods)

//购物车
app.use('/cart/api',cart)

//添加404  异常处理中间件
app.use((req,res,next) => {
  returned(res,404,'找不到路径信息')
})
app.use((err,req,res,next) => {
    returned(res,500,'服务器内部异常',err)
})